﻿using GBT_Tool_v4._0;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace MealInstall
{
    class Program
    {
        /// <summary>
        /// 检测ocx是否已经注册
        /// </summary>
        /// <param name="sClSID">Ocx的CLSID(@"CLSID\{D27CDB70-AE6D-11cf-96B8-444553540000}")</param>
        /// <returns></returns>
        private static bool CheckRegistredDll(string sClSID)
        {
            Microsoft.Win32.RegistryKey keyroot = Microsoft.Win32.Registry.ClassesRoot;
            string ocxkey = sClSID;//{E62D1A95-8299-4B94-85D0-731DC125A60D}
            Microsoft.Win32.RegistryKey rkDll = keyroot.OpenSubKey(ocxkey);
            if (rkDll != null)
            {
                return true;
            }
            else
            {
                return false;
            }
        }

        static void Main(string[] args)
        {
            //grdes6x64
            //{6EDD80CB-9F08-4c71-B406-479E5CB80FCE}
            //gregn6x64
            //{1B5EA181-A38D-4f42-88B2-6AF74CF6D6C0}
            string str = "";
            string cmd = "";
            if (!CheckRegistredDll(@"CLSID\{6EDD80CB-9F08-4c71-B406-479E5CB80FCE}"))
            {
                cmd = "copy /y grdes6x64.dll c:\\windows\\system32\\grdes6x64.dll";
                RegisterDLL.runCmd(cmd, out str);
                Console.WriteLine(str);
                cmd = "regsvr32 /s grdes6x64.dll";
                RegisterDLL.runCmd(cmd, out str);
            }
            if (!CheckRegistredDll(@"CLSID\{1B5EA181-A38D-4f42-88B2-6AF74CF6D6C0}"))
            {
                cmd = "copy /y gregn6x64.dll c:\\windows\\system32\\gregn6x64.dll";
                RegisterDLL.runCmd(cmd, out str);
                Console.WriteLine(str);
                cmd = "regsvr32 /s gregn6x64.dll";
                RegisterDLL.runCmd(cmd, out str);
            }
            Console.WriteLine(str);
            System.Diagnostics.Process.Start(System.AppDomain.CurrentDomain.BaseDirectory + "ExportMealToExcel.exe");
            
        }
    }
}
